class human:
    def __init__(self,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10):
        self.a1=a1
        self.a2=a2
        self.a3=a3
        self.a4=a4
        self.a5=a5
        self.a6=a6
        self.a7=a7
        self.a8=a8
        self.a9=a9
        self.a10=a10
LIST = []
for i in range(1,1001):
    HM = human(i,2,3,4,5,6,7,8,9,10)
    LIST.append(HM)
##################################################################################################################################################################
import openpyxl
workbook = openpyxl.Workbook()
workbook.create_sheet(title='one')
worksheet = workbook['one']
for i in LIST:
    values = list(vars(i).values())#vars,将对象转化为字典
    worksheet.append(values)
workbook.save('user.xlsx') 
##############################################################################################################################################################
import pymysql
class DataBase:
    def __init__(self,host='localhost',user='root',password='root',database='human',port=3306,charset='utf8'):
        self.host = host
        self.user = user
        self.password = password
        self.database = database
        self.port = port
        self.charset = charset

    def update(self,sql,data=None):
        db = pymysql.connect(
            host = self.host,
            user = self.user,
            password = self.password,
            database = self.database,
            port = self.port,
            charset = self.charset
        )
        try:
            with db.cursor() as cursor:
                cursor.execute(sql,data)
                db.commit()
                print('数据操作成功')
        except Exception as e:
            print("数据操作失败！", e)
            db.rollback()
        finally:
            db.close()

    def select(self, sql,data=None):
        db = pymysql.connect(
            host=self.host,
            user=self.user,
            password=self.password,
            database=self.database,
            port=self.port,
            charset=self.charset
        )
        try:
            with db.cursor() as cursor:
                cursor.execute(sql,data)
                result = cursor.fetchall()
                return result
        except Exception as e:
            print('数据查询失败！',e)
        finally:
            db.close()
workbook1 = openpyxl.load_workbook('user.xlsx')
worksheet1 = workbook1['one']
r = worksheet1[1:1000]
DB = DataBase()
for i in r:
    values = [cell.value for cell in i] #从Excel表格里获取的是元组类型的cell，不是单纯的值，其包含了位置信息等
    #这一步将excel中的cell类型的值转换为了列表纯值的形式
    placeholders = ','.join(['%s'] * len(values))
    DB.update(f'insert into text values ({placeholders})',values)


